import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtMultimedia 5.8
import com.amin.classes 1.0  //引入自定义包（类似命名空间）

ApplicationWindow
{
    visible: true
    width: 640
    height: 480
    title: qsTr("CvQml")

    ImageProcessor  //C++类的标识
    {
        id: imgProcessor    //类对象

        onImageProcessed://“on+函数名”，信号--槽自动关联
        {
            imgViewer.setImage(image);//调用QImageViewer类的函数
            imageDrawer.open()
        }
    }

    Camera  //相机类
    {
        id: camera//对象

        imageCapture
        {
            onImageSaved:						//camera的capture方法会自动发送信号imageCaptured(id,url)和imageSaved(id,path),path是本地路径（如C:\Users\Administrator\Pictures\IMG_00000001.jpg）
            {
                imgProcessor.processImage(path) //调用类QImageProcessor的函数
            }
        }
    }

    VideoOutput
    {
        source: camera
        anchors.fill: parent

        MouseArea
        {
            anchors.fill: parent
            onClicked:  //单击鼠标拍图
            {
                camera.imageCapture.capture()   //调用相机函数拍图
            }
        }

        Label
        {
            text: "Touch the screen to take a photo<br>and process it using OpenCV!"
            color: "red"
        }
    }

    Drawer
    {
        id: imageDrawer
        width: parent.width
        height: parent.height

        ImageViewer //C++类QImageViewer的标识
        {
            id: imgViewer   //类对象
            anchors.fill: parent

            Label
            {
                text: "Swipe from right to left<br>to return to capture mode!"
                color: "red"
            }
        }
    }
}
